<?php
class ltdcc
{
	public static function loadurl($url,$post,$cookies)
	{
		$timeout=200;
		$ch = curl_init(); 
		curl_setopt($ch, CURLOPT_URL, $url); 
		curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/6.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.7) Gecko/20050414 Firefox/1.0.3"); 
		curl_setopt($ch, CURLOPT_POSTFIELDS,$post);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
		curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies); 
		curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies); 
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
		$result = curl_exec($ch);
		curl_close($ch);
		return $result;
	}
	public static function loginltd($cookies)
	{
		
		$UrlLogin="http://ltdcc.ru?s=login";
		
		$Login=self::loadurl($UrlLogin, $Post,$cookies);
		return $Login;
	}
	public static function logoutltd()
	{
		$url="http://ltdcc.ru/?s=out";
		self::loadurl($url, "0");
		return true;
	}
	public static function GetContents($string,$start,$end)
	{
		$temp=explode($start,$string);
		$Result=explode($end,$temp[1]);
		return $Result[0];
	}
	public static function SearchCountryLtd()
	{
		$a=rand(1000,100000);
		$cookies="cookiesx/".$a."cookies.txt";
		$Login=self::loginltd($cookies);
		$url="http://ltdcc.ru/?s=cc";
		$SearchCountry=self::loadurl($url, "0",$cookies);
		$Start='<option value="all">All</option>';
		$End="</select>";
		if(empty($SearchCountry))
		{
			return 0;
		}
		else
		{
			$GetContents=self::GetContents($SearchCountry, $Start, $End);
			$delimiter='</option>';
			$arryCountry=explode($delimiter,$GetContents);
			$totalCountry=count($arryCountry)-1;
			for($i=0;$i<$totalCountry;$i++)
			{
				$line=$arryCountry[$i];
				$start='<option value="';
				$end='">';
				$country_code=self::GetContents($line, $start, $end);
				$country_code=strtolower($country_code);
				$arrayReturn[]=$country_code;
			}
	
			return $arrayReturn;
		}
	}
	public static function GetStateLtd($Country)
	{
		$a=rand(1000,100000);
		$cookies="cookiesx/".$a."cookies.txt";
		self::loginltd($cookies);
		$url="http://ltdcc.ru/?s=cc&ss=getstates&country=$Country";
		$GetState=self::loadurl($url, "0");
		$GetContents="<select name='state' id='state' >$GetState</select>";
		return $GetState;
	}
	public static function SearchCC($Country,$Type,$Bin,$State,$price)
	{
		$a=rand(1000,100000);
		$cookies="cookiesx/".$a."cookies.txt";

		if(empty($State))
		{
			$State="all";
		}
		$UrlSearch="http://ltdcc.ru/?s=cc";
		if($Bin==0)
		{
			$Bin="";
		}
		if(!empty($Type))
		{
			$Bin=$Type;
		}
		$Post="country=$Country&type=$Type&bin=$Bin&state=$State&exp_month=any&exp_year=any&city=all&price=all&zip=&type=&search=Search";
		self::loginltd($cookies);
		$GetCcInfo=self::loadurl($UrlSearch, $Post,$cookies);
		if(empty($GetCcInfo))
		{
			return 0;
		}
		else 
		{
			$Start="</tr>";
			$GetArr=explode($Start,$GetCcInfo);
			$NumsRows=count($GetArr)-2;
			$ArrReturn=array();

			for($i=15;$i<$NumsRows;$i++)
			{
				
				$Search=array("</td>","<tr>");
				$Replace=array("","");
				$IdReturn=$i-15;
				$ArrLater=str_replace($Search,$Replace, $GetArr[$i]);
				$Delimit="<td class=price>";
				$Arrcc=explode($Delimit,$ArrLater);
				$ex=rtrim(trim($Arrcc[3]));
				$exM=substr($ex,0,2);
				$exY="20".substr($ex,3,2);
				$ArrReturn["$IdReturn"]['bin']=rtrim(trim($Arrcc[1]));
				$ArrReturn["$IdReturn"]['name']=rtrim(trim($Arrcc[2]));
				$ArrReturn["$IdReturn"]['exM']=rtrim(trim($exM));
				$ArrReturn["$IdReturn"]['exY']=rtrim(trim($exY));
				$ArrReturn["$IdReturn"]['city']=rtrim(trim($Arrcc[4]));
				$ArrReturn["$IdReturn"]['state']=rtrim(trim($Arrcc[5]));
				$ArrReturn["$IdReturn"]['country']=rtrim(trim($Arrcc[6]));
				$ArrReturn["$IdReturn"]['zip']=rtrim(trim($Arrcc[7]));
				$ArrReturn["$IdReturn"]['price']=$price;
				$ArrSearch=array('<input type="checkbox" name="ccs[]" value="','">');
				$ArrReplace=array('','');
				$StrCCid=str_replace($ArrSearch,$ArrReplace,$Arrcc[9]);
				$ArrReturn[$IdReturn]['ccid']=$StrCCid;

			}
			return $ArrReturn;
		}
		
	}
	public static function AddToCart($ccid,$cookies)
	{
		
		
		self::loginltd($cookies);
		$Url="http://ltdcc.ru/?s=cart";
		$Post=NULL;
		foreach($ccid as $showCcId)
		{
			$Post=$Post."&ccs%5B%5D=".$showCcId;
		}
		$Post2="save=Add+to+cart";
		$Post=$Post2.$Post;
		$AddToCart=self::loadurl($Url, $Post,$cookies);
		return $AddToCart;
	}
	public static function CheckOut($ccid)
	{
		$a=rand(1000,100000);
		$cookies="cookiesx/".$a."cookies.txt";
		$UrlCheckout="http://ltdcc.ru/?s=cart&checkout=2";
		$AddToCart=self::AddToCart($ccid,$cookies);
		$Checkout=self::loadurl($UrlCheckout, "0",$cookies);
		if(stristr($Checkout,"Checkout")==TRUE)
		{
			return FALSE;
		}
		else 
		{
				return TRUE;
		}

		
	
	}
	public static function CheckBalanceLtd()
	{
		$a=rand(1000,100000);
		$cookies="cookiesx/".$a."cookies.txt";
		$Login=self::loginltd($cookies);
		$Start="Balance: <b>";
		$End="</b><br>";
		$Balance=self::GetContents($Login, $Start, $End);
		return $Balance;
	}
	public static function CheckCc($ccnum,$exm,$exy)
	{
		$a=rand(1000,100000);
		$cookies="plan/cookiesx/".$a."cookies.txt";
		self::loginltd($cookies);
		$urlcheck="http://ltdcc.ru/?s=my";
		$Check=self::loadurl($urlcheck, "0",$cookies);
		$start='<td id="'.$ccnum.'">';
		$end="</td>";
		$ArrCcCheck=self::GetContents($Check, $start, $end);
		if(stristr($ArrCcCheck, "Approved")==TRUE)
		{
			return 1; // live
		}
		else if(stristr($ArrCcCheck, "Declined")==TRUE)
		{
			return 0; // die
		}
		else
		{
			return 2;
		}

	}
	public static function GetCC($Quality,$price,$UserID,$Orderid,$Country)
	{
		$checkerId=buycc::findChecker("ltd");
		$a=rand(1000,100000);
		$cookies="cookiesx/".$a."cookies.txt";
		self::loginltd($cookies);
		$UrlCheckout="http://ltdcc.ru/?s=my";
		$Load=self::loadurl($UrlCheckout, "0",$cookies);
		echo $Load;
		$Start='<table width="100%" border="1">';
		$End="</table>";
		$ArrSplit=self::GetContents($Load, $Start,$End);
		$delimiter='</tr>';
		$ArrCCinfo=explode($delimiter,$ArrSplit);
		for($i=0;$i<$Quality;$i++)
		{
			
			$CcTdTr=$ArrCCinfo[$i];
			$ArrGetCC=explode("</td>",$CcTdTr);
			$CCLine=$ArrGetCC[1];
			$CCLine=str_replace("<td>", "", $CCLine);
			$ArrCC=explode("|",$CCLine);
			$CcNums=rtrim(trim($ArrCC[0]));
			$CCbin=substr($CcNums, 0,6);
			$ex=rtrim(trim($ArrCC[1]));
			$Exm=substr($ex,0,2);
			$Exy="20".substr($ex,2,2);
			$ccv=rtrim(trim($ArrCC[2]));
			$CCNumbers=hash::hashccv($CcNums,$Exm,$Exy,$ccv);
			$ArrLater=array($ArrCC[0],$ex,$ccv);
			$ArrOther=array_diff($ArrCC,$ArrLater);
			$IsOther=null;
			if(substr($CCNumbers, 0,1)==4)
			{
				$Typecc="VISA";
			}
			else if(substr($CCNumbers, 0,1)==5)
			{
				$Typecc="MASTER";
			}
			else if(substr($CCNumbers, 0,1)==3)
			{
				$Typecc="AMEX";
			}
			else if(substr($CCNumbers, 0,1)==6)
			{
				$Typecc="DIS";
			}
			else 
			{
				$Typecc="unknow";
			}
			foreach($ArrOther as $Other)
			{
				$IsOther=$IsOther."|".$Other;
			}
			$InsertCC=database::Insert('ccinfo', array(
			'TypeCC' => $Typecc,
			'CCnumber' => $CCNumbers,
			'ExMonth' => $Exm,
			'ExYear' => $Exy,
			'CCV2' => $ccv,
			'Others' => $IsOther,
			'site' => 'ltd',
			'country' => $Country,
			'pricesell' => $price,
			'userid' => $UserID,
			'orderid' => $Orderid,
			'checker_id' => $checkerId
			));
		}
		
		
	}
}

?>